package vg.modules.backlight;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import vg.core.AUserInterface;
import vg.core.AUserInterfaceElement;
import vg.core.IGraphView;
import vg.core.event.AUIEvent;
import vg.core.event.UIEventChangeView;
import vg.core.exception.PluginException;
import vg.core.plugin.IPlugin;
import vg.core.plugin.PluginParameter;
import vg.core.storableGraph.StorableSubGraph;
import vg.core.storableGraph.StorableVertex;
import vg.modules.backlight.components.CriticalPathSearcher;
import vg.modules.backlight.components.CycleSearcher;
import vg.modules.backlight.components.PathsSearcher;
import vg.userInterface.scaling.ZoomPanel;
public class PathSelectingPlugin implements IPlugin {
@Override
public void install(PluginParameter parameter) throws PluginException {
new PathSelectingPanel(parameter.userInterface);
}
private class PathSelectingPanel extends AUserInterfaceElement {
private AUserInterface userInterface;
private CycleSearcher cycleSearcher;
private PathsSearcher pathsSearcher;
private CriticalPathSearcher criticalPathSearcher;
private JToolBar toolBar;
private Observer observer;
private IGraphView view;
public PathSelectingPanel(AUserInterface userinterface) {
super("PathSelectingPlugin", null);
this.observer = new Observer() {
public void update(Observable o, Object arg) {
checkView();
}
};
this.pathsSearcher = new PathsSearcher();
this.criticalPathSearcher = new CriticalPathSearcher();
this.cycleSearcher = new CycleSearcher();
toolBar = new JToolBar();
toolBar.setFloatable(false);
toolBar.add(cycleSearcher.getView());
toolBar.add(pathsSearcher.getView());
toolBar.add(criticalPathSearcher.getView());
userinterface.addInstrument(this);
}
@Override
public JComponent getView() {
return toolBar;
}
@Override
public void update(Observable o, Object arg) {
if (arg instanceof AUIEvent) {
AUIEvent event = (AUIEvent) arg;
switch (event.getType()) {
case DEF_CHANGE_UI_STYLE: {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
synchronized (PathSelectingPanel.this) {
SwingUtilities.updateComponentTreeUI(PathSelectingPanel.this.toolBar);
}
}
});
break;
}
case DEF_CHANGE_VIEW: {
if (this.view != null) {
this.view.deleteObserver(this.observer);
}
UIEventChangeView bufEvent = (UIEventChangeView) event;
this.view = bufEvent.getView();
if (this.view != null) {
this.view.addObserver(this.observer);
}
cycleSearcher.changeView(view);
criticalPathSearcher.changeView(view);
pathsSearcher.changeView(view);
checkView();
break;
}
}
}
}
/**
* This method checks view on conditional (selection subgraph must contain one vertex).
*/
private void checkView() {
if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
checkView();
}
});
return;
}
boolean cycleCheck = false;
boolean pathCheck = false;
if (this.view != null) {
StorableSubGraph ssg = this.view.getSelectionSubGraph();
if (ssg != null) {
List<StorableVertex> lsv = ssg.getVertices();
if (lsv != null) {
cycleCheck = (lsv.size() == 1);
pathCheck = (lsv.size() == 2);
}
}
}
cycleSearcher.setEnabled(cycleCheck);
criticalPathSearcher.setEnabled(pathCheck);
pathsSearcher.setEnabled(pathCheck);
}
}
}